﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;

public partial class role_Role : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    public string [] GetValue()
    {
        List<string> lst = new List<string>();
        foreach (ListItem c in cbklstCid.Items)
        {
            if (c.Selected)
            {
                lst.Add( c.Value);
            }
        }
        if (lst.Count > 0)
        {
            lst.Add(Pid);
        }
        return lst.ToArray();
    }

    public void SetValue(int roleId)
    {
        CMSModel.CMSEntities cms = DBManager.GetCmsEmtity();
        var temp = cms.Power.Where(x => x.Pid == Pid).Select(x => new { x.Id,x.Name});
        cbklstCid.DataSource = temp;
        cbklstCid.DataTextField = "Name";
        cbklstCid.DataValueField = "Id";
        cbklstCid.DataBind();
        cbkPid.Text = cms.Power.Where(x => x.Id == Pid).First().Name;
        var cids= cms.Role_Power.Where(x => x.RoleId == roleId);
        foreach (ListItem item in cbklstCid.Items)
        {
            foreach (var c in cids)
            {
                if (c.Pow_Id.ToString() == item.Value)
                {
                    item.Selected = true;
                    cbkPid.Checked = true;
                }
            }
        }
    }

    public string Pid
    {
        get
        {
            return ViewState["pid"].ToString();
        }
        set
        {
            ViewState["pid"] = value;
        }
    }

}